{extend name='public/base' /}
{block name='content'}
{include file='public/content_header' /}
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="card">
                <!-- 表单头部 -->
                <div class="card-header">
                    <div class="btn-group">
                        <a class="btn flat btn-sm btn-default BackButton">
                            <i class="fas fa-arrow-left"></i>
                            返回
                        </a>
                    </div>
                </div>
                <!-- 表单 -->
                <form id="dataForm" class="form-horizontal dataForm" action="" method="post"
                      enctype="multipart/form-data">
                    <!-- 表单字段区域 -->
                    <div class="card-body">
                        <div class="form-group row">
                            <label for="avatar" class="col-sm-2 col-form-label">照片</label>
                            <div class="col-sm-10 col-md-4 formInputDiv">
                                <div class="input-group">
                                    <input id="avatar_file" name="avatar_file" type="file" class="file-loading "
                                           data-initial-preview="{if isset($data)}{$data.avatar}{/if}">
                                    <input name="avatar" id="avatar" value="{$data.avatar|default=''}" hidden
                                           placeholder="请上传图片" class="fieldImage">
                                    <script>
                                        initUploadImg('avatar');
                                    </script>
                                </div>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label for="name" class="col-sm-2 col-form-label">姓名</label>
                            <div class="col-sm-10 col-md-4 formInputDiv">
                                <input id="name" name="name" value="{$data.name|default=''}" placeholder="请输入姓名"
                                       type="text" class="form-control fieldText">
                            </div>
                        </div>
                        <div class="form-group row">
                            <label for="department_id" class="col-sm-2 col-form-label">部门</label>
                            <div class="col-sm-10 col-md-4 formInputDiv">
                                <select name="department_id" id="department_id"
                                        class="form-control select2bs4 fieldSelect" data-placeholder="请选择部门">
                                    {$department_list|raw|default=''}
                                </select>
                            </div>
                        </div>
                        <script>
                            $('#department_id').select2({
                                theme: 'bootstrap4'
                            });
                        </script>
                        <div class="form-group row">
                            <label for="position_id" class="col-sm-2 col-form-label">职位</label>
                            <div class="col-sm-10 col-md-4 formInputDiv">
                                <select name="position_id" id="position_id" class="form-control select2bs4 fieldSelect"
                                        data-placeholder="请选择职位">
                                    <option value=""></option>
                                    {foreach name='position_list' id='item'}
                                    <option value="{$item.id}" {if isset($data) &&
                                            $data.position_id==$item.id}selected{/if}>
                                        {$item.name}
                                    </option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        <script>
                            $('#position_id').select2({
                                theme: 'bootstrap4'
                            });
                        </script>
                        <div class="form-group row">
                            <label for="job_number" class="col-sm-2 col-form-label">工号</label>
                            <div class="col-sm-10 col-md-4 formInputDiv">
                                <div class="input-group">
                                    <input id="job_number" name="job_number" value="{$data.job_number|default='0'}"
                                           placeholder="请输入工号" type="number" class="form-control fieldNumber">
                                </div>
                            </div>
                        </div>
                        <script>
                            $('#job_number')
                                .bootstrapNumber({
                                    upClass: 'success',
                                    downClass: 'primary',
                                    center: true
                                });
                        </script>
                        <div class="form-group row">
                            <label for="mobile" class="col-sm-2 col-form-label">手机号</label>
                            <div class="col-sm-10 col-md-4 formInputDiv">
                                <input id="mobile" name="mobile" value="{$data.mobile|default=''}" placeholder="请输入手机号"
                                       type="tel" maxlength="11" class="form-control fieldMobile">
                            </div>
                        </div>
                        <div class="form-group row">
                            <label for="email" class="col-sm-2 col-form-label">邮箱</label>
                            <div class="col-sm-10 col-md-4 formInputDiv">
                                <input id="email" name="email" value="{$data.email|default=''}" placeholder="请输入邮箱"
                                       type="text" class="form-control fieldText">
                            </div>
                        </div>
                        <div class="form-group row">
                            <label for="birthday" class="col-sm-2 col-form-label">生日</label>
                            <div class="col-sm-10 col-md-4 formInputDiv">
                                <input id="birthday" readonly name="birthday" value="{$data.birthday|default=''}"
                                       placeholder="请选择生日" type="text" class="form-control filedDate">
                            </div>
                        </div>
                        <script>
                            laydate.render({
                                elem: '#birthday',
                            });
                        </script>
                        <div class="form-group row">
                            <label for="hired_date" class="col-sm-2 col-form-label">入职日期</label>
                            <div class="col-sm-10 col-md-4 formInputDiv">
                                <input id="hired_date" readonly name="hired_date" value="{$data.hired_date|default=''}"
                                       placeholder="请选择入职日期" type="text" class="form-control filedDate">
                            </div>
                        </div>
                        <script>
                            laydate.render({
                                elem: '#hired_date',
                            });
                        </script>
                        <div class="form-group row">
                            <label for="is_boss" class="col-sm-2 col-form-label">是否为老板</label>
                            <div class="col-sm-10 col-md-4 formInputDiv">
                                <input class="input-switch" id="is_boss" value="1" {if(!isset($data)
                                       ||$data.is_boss==1)}checked{/if} type="checkbox"/>
                                <input class="switch fieldSwitch" placeholder="是否为老板" name="is_boss"
                                       value="{$data.is_boss|default='0'}" hidden/>
                            </div>
                        </div>

                        <script>
                            $('#is_boss').bootstrapSwitch({
                                onText: "是",
                                offText: "否",
                                onColor: "success",
                                offColor: "danger",
                                onSwitchChange: function (event, state) {
                                    $(event.target).closest('.bootstrap-switch').next().val(state ? '1' : '0').change();
                                }
                            });
                        </script>
                        <div class="form-group row">
                            <label for="is_leader" class="col-sm-2 col-form-label">是否所属部门领导</label>
                            <div class="col-sm-10 col-md-4 formInputDiv">
                                <input class="input-switch" id="is_leader" value="1" {if(!isset($data)
                                       ||$data.is_leader==1)}checked{/if} type="checkbox"/>
                                <input class="switch fieldSwitch" placeholder="是否所属部门领导" name="is_leader"
                                       value="{$data.is_leader|default='0'}" hidden/>
                            </div>
                        </div>

                        <script>
                            $('#is_leader').bootstrapSwitch({
                                onText: "是",
                                offText: "否",
                                onColor: "success",
                                offColor: "danger",
                                onSwitchChange: function (event, state) {
                                    $(event.target).closest('.bootstrap-switch').next().val(state ? '1' : '0').change();
                                }
                            });
                        </script>
                        <div class="form-group row">
                            <label for="sort_number" class="col-sm-2 col-form-label">排序</label>
                            <div class="col-sm-10 col-md-4 formInputDiv">
                                <div class="input-group">
                                    <input id="sort_number" name="sort_number"
                                           value="{$data.sort_number|default='1000'}" placeholder="请输入排序" type="number"
                                           class="form-control fieldNumber">
                                </div>
                            </div>
                        </div>
                        <script>
                            $('#sort_number')
                                .bootstrapNumber({
                                    upClass: 'success',
                                    downClass: 'primary',
                                    center: true
                                });
                        </script>
                        <div class="form-group row">
                            <label for="status" class="col-sm-2 col-form-label">是否启用</label>
                            <div class="col-sm-10 col-md-4 formInputDiv">
                                <input class="input-switch" id="status" value="1" {if(!isset($data)
                                       ||$data.status==1)}checked{/if} type="checkbox"/>
                                <input class="switch fieldSwitch" placeholder="是否启用" name="status"
                                       value="{$data.status|default='1'}" hidden/>
                            </div>
                        </div>

                        <script>
                            $('#status').bootstrapSwitch({
                                onText: "是",
                                offText: "否",
                                onColor: "success",
                                offColor: "danger",
                                onSwitchChange: function (event, state) {
                                    $(event.target).closest('.bootstrap-switch').next().val(state ? '1' : '0').change();
                                }
                            });
                        </script>
                    </div>
                    <!-- 表单底部 -->
                    <div class="card-footer">
                        <div class="row">
                            <div class="col-sm-2">
                            </div>

                            <div class="col-sm-10 col-md-4 formInputDiv">

                                <div class="btn-group">
                                    <button type="submit" class="btn btn-sm btn-primary dataFormSubmit">
                                        保 存
                                    </button>
                                </div>
                                <div class="btn-group">
                                    <button type="reset" class="btn btn-sm btn-default dataFormReset">
                                        重 置
                                    </button>
                                </div>

                                {if !isset($data)}
                                <div class="btn-group float-right createContinueDiv">
                                    <input type="checkbox" class="form-check-input" value="1" id="_create"
                                           name="_create" title="继续添加数据">
                                    <label class="form-check-label" for="_create">继续添加</label>
                                </div>
                                {/if}
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</section>
<script>
    /** 表单验证 **/
    $('#dataForm').validate({
        rules: {
            'avatar': {
                required: true,

            },
            'name': {
                required: true,

            },
            'department_id': {
                required: true,

            },
            'position_id': {
                required: true,

            },
            'job_number': {
                required: true,

            },
            'mobile': {
                required: true,

            },
            'email': {
                required: true,

            },
            'birthday': {
                required: true,

            },
            'hired_date': {
                required: true,

            },
            'is_boss': {
                required: true,

            },
            'is_leader': {
                required: true,

            },
            'sort_number': {
                required: true,

            },
            'status': {
                required: true,

            },

        },
        messages: {
            'avatar': {
                required: "照片不能为空",

            },
            'name': {
                required: "姓名不能为空",

            },
            'department_id': {
                required: "部门不能为空",

            },
            'position_id': {
                required: "职位不能为空",

            },
            'job_number': {
                required: "工号不能为空",

            },
            'mobile': {
                required: "手机号不能为空",

            },
            'email': {
                required: "邮箱不能为空",

            },
            'birthday': {
                required: "生日不能为空",

            },
            'hired_date': {
                required: "入职日期不能为空",

            },
            'is_boss': {
                required: "是否为老板不能为空",

            },
            'is_leader': {
                required: "是否所属部门领导不能为空",

            },
            'sort_number': {
                required: "排序不能为空",

            },
            'status': {
                required: "是否启用不能为空",

            },

        }
    });
</script>
{/block}